package com.hundsun.cprs.yyt.service.match.core.stat;

import java.util.concurrent.atomic.AtomicLong;

/**
 * 用户份额日交易数据汇总
 * 
 * @author fish
 * 
 */
public class MemberTradesStatistics {

	//4个数字都应该为整数
	private AtomicLong bought = new AtomicLong(0);// 已经买入份额

	private AtomicLong sold = new AtomicLong(0);// 已经卖出份额

	private AtomicLong buying = new AtomicLong(0);// 挂单买份额(未买入)

	private AtomicLong selling = new AtomicLong(0);// 挂单卖份额(为卖出)

	/**
	 * 得到(已买份额+未份额)-(已卖份额),如果卖的多，返回负值
	 * 
	 * @return
	 */
	public long getBoughtSubSold() {
		return bought.longValue()+ buying.longValue() - sold.longValue();
	}
	
	/**
	 * 得到(已卖+未卖)-(已买份额)
	 * @return
	 */
	public long getSellSubBought(){
		return sold.longValue() + selling.longValue() - bought.longValue();
	}

	/**
	 * 增加委买份额
	 * 
	 * @param num
	 */
	public void buyEntrust(long num) {
		buying.getAndAdd(Math.abs(num));
	}
	
	/**
	 * 减少委买份额
	 * @param entrustAmount
	 */
	public void reduceBuyEntrust(Long num) {
		buying.getAndAdd(-Math.abs(num));
	}

	/**
	 * 增加委卖份额
	 * 
	 * @param num
	 */
	public void sellEntrust(long num) {
		selling.getAndAdd(Math.abs(num));
	}
	
	
	/**
	 * 减少委卖份额
	 * @param entrustAmount
	 */
	public void reduceSellEntrust(Long num) {
		selling.getAndAdd(-Math.abs(num));
	}
	
	/**
	 * 买入成功
	 */
	public void boughtIn(long num){
		long n = Math.abs(num);
		buying.getAndAdd(-n);
		bought.getAndAdd(n);
	}
	
	/**
	 * 买入成功
	 */
	public void boughtInByThird(long num){
		long n = Math.abs(num);
		bought.getAndAdd(n);
	}
	
	
	/**
	 * 卖出成功
	 */
	public void soldOut(long num){
		long n = Math.abs(num);
		selling.getAndAdd(-n);
		sold.getAndAdd(n);
	}
	
	/**
	 * 卖出成功
	 */
	public void soldOutOfThird(long num){
		long n = Math.abs(num);
		sold.getAndAdd(n);
	}
	
	/**
	 * 得到未成交挂单买总量
	 * @return
	 */
	public long getBuying(){
		return buying.longValue();
	}

	public AtomicLong getBought() {
		return bought;
	}

	public void setBought(AtomicLong bought) {
		this.bought = bought;
	}

	public AtomicLong getSold() {
		return sold;
	}

	public void setSold(AtomicLong sold) {
		this.sold = sold;
	}

	public AtomicLong getSelling() {
		return selling;
	}

	public void setSelling(AtomicLong selling) {
		this.selling = selling;
	}

	public void setBuying(AtomicLong buying) {
		this.buying = buying;
	}

}
